import gradio as gr
import requests

# 替换为你的DeepSeek API密钥和端点URL
DEEPSEEK_API_KEY = "你的api"
DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions"


def ask_deepseek(question):
    headers = {
        "Authorization": f"Bearer {DEEPSEEK_API_KEY}",
        "Content-Type": "application/json"
    }

    data = {
        "model": "deepseek-chat",  # 根据你的API文档选择合适的模型
        "messages": [
            {"role": "user", "content": question}
        ]
    }

    response = requests.post(DEEPSEEK_API_URL, headers=headers, json=data)

    if response.status_code == 200:
        result = response.json()
        return result['choices'][0]['message']['content']
    else:
        return f"Error: {response.status_code}, {response.text}"


# 创建Gradio界面并设置主题
iface = gr.Interface(
    fn=ask_deepseek,
    inputs=gr.Textbox(lines=2, placeholder="请输入你的问题...", label="问题"),
    outputs=gr.Textbox(lines=4, label="答案"),
    title="DeepSeek 问答系统",
    description="输入你的问题，DeepSeek 将为你提供答案。",
    theme="soft"  # 设置主题，可选值：default, soft, glass, monochrome 等
)

custom_theme = gr.themes.Default(
    primary_hue="blue",  # 主色调
    secondary_hue="teal",  # 副色调
    font=[gr.themes.GoogleFont("Open Sans"), "sans-serif"]  # 字体
)

# 启动Gradio应用
iface.launch()